package com.food.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.food.admin.entity.AccountInfo;
import com.food.admin.exception.MyParameterException;
import com.food.admin.form.AccountInfoUpdateForm;
import com.food.admin.mapper.AccountInfoMapper;
import com.food.admin.model.Result;
import com.food.admin.service.AccountInfoService;
import com.food.admin.util.JwtUtil;
import com.food.admin.util.RedisUtil;
import com.food.admin.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 帅得一
 * @since 2023年06月13日
 */
@RestController
@RequestMapping("/accountInfo")
@Api(tags = "管理员信息接口")
public class AccountInfoController {

    @Autowired
    private AccountInfoService accountInfoService;

    @Autowired
    private AccountInfoMapper accountInfoMapper;


    @PostMapping("/updateAccountInfo")
    @ApiOperation("修改管理员信息")
    public Result updateAccountInfo(@RequestBody @Valid AccountInfoUpdateForm form, BindingResult br) throws Exception{
        if (br.hasErrors()) {
            List<ObjectError> allErrors = br.getAllErrors();
            for (ObjectError allError : allErrors) {
                //获取打印提示信息
                System.out.println(allError.getDefaultMessage());
            }
            throw new MyParameterException(500, "参数校验失败");
        }
        AccountInfo accountInfo=accountInfoService.updateAccountInfo(form);
        return Result.success("200","修改管理员信息成功",accountInfo);
    }

    @GetMapping("/list")
    @ApiOperation("查询所有管理员信息")
    public Result list() throws Exception{
        List<AccountInfo> list = accountInfoService.list();
        return Result.success("200","查询所有管理员信息成功",list);
    }

    @GetMapping("/showMyInfo")
    @ApiOperation("查询个人信息")
    public Result showMyInfo() throws Exception{

       AccountInfo accountInfo=accountInfoService.showMyInfo();
       return Result.success("200","查询个人信息成功",accountInfo);
    }

}

